from pydantic import BaseModel, Field
from typing import Generic, TypeVar, Optional

# 定义泛型类型，用于动态指定返回数据的类型
T = TypeVar('T')

class BaseResponse(BaseModel, Generic[T]):
    code: int = Field(default=200, description="状态码")
    message: str = Field(default="success", description="返回消息")
    data: Optional[T] = Field(default=None, description="返回数据")

    class Config:
        json_schema_extra = {
            "example": {
                "code": 200,
                "message": "success",
                "data": None
            }
        }